package jspservlet.vo;

import org.json.*;
import java.io.*;
import java.net.*;

public class Connection {

    public JSONObject transport(JSONObject deliverMessage) {

        Socket socket = null;

        try {

            socket = new Socket("123.56.66.9", 28880);
            System.out.println("Socket=" + socket);

            OutputStream os = socket.getOutputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write(deliverMessage.toString());

            DataInputStream inputstream = new DataInputStream(socket.getInputStream());

            int c;
            String str = "";
            do {
                c = inputstream.read();
                str += (char) c;
            } while (inputstream.available() > 0);

            JSONObject returnMessage=new JSONObject(str);

            return returnMessage;

        } catch (Exception e) {
            e.printStackTrace();
            JSONObject returnMessage=new JSONObject();

            returnMessage.put("success",0);
            returnMessage.put("errmsg",e.toString());
            return returnMessage;
        }

    }
    
}